const car={
    state:{
        carList:[]
    },
    mutations:{
        JOIN_CAR(state,item){
            const info =state.carList.find(v=>v.goodsName===item.goodsName);
            if(info){
                info.buyNum++;
            }else{
                state.carList.unshift({
                    ...item,
                    buyNum:1
                })
            }
        }
    },
    getters:{
        sumPrice(state){
            return state.carList.reduce((sum,item)=>{
                sum+=item.buyNum*item.goodsPrice;
                return sum;
            },0)
        }
    }
}
export default car;